//
//  MainView.swift
//  MakeMoney
//
//  Created by Fan ZhiQiang on 2024/12/6.
//

import SwiftUI

struct MainView: View {
    @State private var pathStore = PathStore()
    @Environment(\.scenePhase) private var scenePhase
    
    var body: some View {
        NavigationStack(path: $pathStore.path) {
            VStack(alignment: .leading) {
                HStack(alignment: .top, spacing: 15) {
                    MainFuncButtonView(title: "查看\n列表") {
                        pathStore.path.append(MainAllListPath())
                    }
                    MainFuncButtonView(title: "查看\n概率") {
                        pathStore.path.append(MainEveryBallPath())
                    }
                    MainFuncButtonView(title: "查看\n位置") {
                        pathStore.path.append(MainPositionPath())
                    }
                    MainFuncButtonView(title: "排除\n方法") {
                        
                    }
                    Spacer()
                }
                .frame(maxWidth: .infinity)
                .padding(.leading, 20)
                Spacer()
            }
            .frame(maxWidth: .infinity)
            .navigationTitle("首页")
            .navigationDestination(for: MainAllListPath.self) { _ in
                MainAllListView(pathStore: pathStore)
            }
            .navigationDestination(for: MainEveryBallPath.self) { _ in
                MainEveryBallView(pathStore: pathStore)
            }
            .navigationDestination(for: MainPositionPath.self) { _ in
                MainPositionView(pathStore: pathStore)
            }
            .navigationDestination(for: YearListPath.self) { _ in
                YearListView(pathStore: pathStore)
            }
            .navigationDestination(for: ConditionSelectPath.self) { _ in
                ConditionSelectView(pathStore: pathStore)
            }
            .navigationDestination(for: TestPath.self) { _ in
                TestView()
            }
        }
        .onChange(of: scenePhase) { phase, newPhase in
            if phase == .background {
                pathStore.save()
            }
        }
    }
}

#Preview {
    MainView()
}

/**
 List(lotteryYears, id: \.self) { year in
//                NavigationLink(value: year) {
//                    Text(String(year))
//                        .padding(.vertical, 10)
//                }
     //.listRowInsets(.init(top: 10, leading: 20, bottom: 10, trailing: 20))
     //.listRowSeparatorTint(.accent)
     //.listRowSeparator(.hidden, edges: .bottom)
     Button(String(year) + "年") {
         print()
         pathStore.path.append(year)
     }
 }
 .navigationDestination(for: Int.self) { path in
     YearView(yearIdRange: getYearId(with: path), pathStore: pathStore)
 }
 */


//            ScrollView {
//                LazyVGrid(columns: columns) {
//                    ForEach(1..<36) { num in
//                        VStack {
//                            Text("\(num)")
//                                .font(.title)
//                                .foregroundStyle(.white)
//                                .frame(minWidth: 150, idealWidth: 150, maxWidth: 150, minHeight: 150, idealHeight: 150, maxHeight: 150, alignment: .center)
//                                .background(.blue)
//                                .clipShape(.circle)
//                        }
//                    }
//                }
//            }
//            Form {
//                Section {
//                    Button("按年份查看") {
//                        pathStore.path.append(YearListPath())
//                    }
//                }
//                Section {
//                    Button("按条件查看") {
//                        pathStore.path.append(ConditionSelectPath())
//                    }
//                }
//                Section {
//                    Button("查看数据") {
//                        pathStore.path.append(TestPath())
//                    }
//                }
//            }
